const initState = [
    {id:'001',name:'吃饭',done:true},
    {id:'002',name:'睡觉',done:true},
    {id:'003',name:'打代码',done:false},
    {id:'004',name:'逛街',done:false}
]
export default function listReducer(preState = initState,action){
    const {type,data} = action
    switch(type){
        case 'add':
            return [data,...preState]
        case 'update':
            return preState.map(item => {
                if(data.id === item.id) return {...item,done:data.done}
                else return item
            })
        case 'checkAll':
            return preState.map(item => ({...item,done:data}))
        case 'deleteDone':
            return preState.filter(item => !item.done)
        case 'delete':
            return preState.filter(item => data!==item.id)
        default:
            return preState
    }
}